package de.hska.reka.websockets.annotationProcessors;

import java.lang.reflect.Field;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.ReflectionUtils.FieldCallback;

import de.hska.reka.websockets.annotations.WebSocketCallback;

@Component
public class WebsocketCallbackAnnotationProcessor implements BeanPostProcessor,
ApplicationContextAware  {
	private ApplicationContext applicationContext;
	
	public Object postProcessAfterInitialization(Object bean, String beanName)
			throws BeansException {
		return bean;
	}

	public Object postProcessBeforeInitialization(Object bean, String beanName)
			throws BeansException {
		ReflectionUtils.doWithFields(bean.getClass(), new FieldCallback() {
			
			public void doWith(Field arg0) throws IllegalArgumentException,
					IllegalAccessException {
				if(arg0.getDeclaringClass().isAnnotationPresent(WebSocketCallback.class)) {
					
				}
			}
		});
		return bean;
	}

	public void setApplicationContext(ApplicationContext arg0)
			throws BeansException {
		this.applicationContext = applicationContext;
	}

}
